﻿#region << 文 件 说 明 >>

/*----------------------------------------------------------------
// 文件名称：RadarChart
// 创 建 者：杨程
// 创建时间：2022/3/11 14:53:16
// 文件版本：V1.0.0
// ===============================================================
// 功能描述：
//
//
//----------------------------------------------------------------*/

#endregion

namespace Vampirewal.Core.WPF.Theme;

/// <summary>
/// 雷达图控件
/// </summary>
//public class RadarChart : Control
//{
//    public ObservableCollection<RadarModel> RadarArray
//    {
//        get { return (ObservableCollection<RadarModel>)GetValue(RadarArrayProperty); }
//        set { SetValue(RadarArrayProperty, value); }
//    }

//    public static readonly DependencyProperty RadarArrayProperty =
//        DependencyProperty.Register("RadarArray", typeof(ObservableCollection<RadarModel>), typeof(RadarChart), new PropertyMetadata(null));

//    public Brush RadarChartTitleForeground
//    {
//        get { return (Brush)GetValue(RadarChartTitleForegroundProperty); }
//        set { SetValue(RadarChartTitleForegroundProperty, value); }
//    }

//    // Using a DependencyProperty as the backing store for RadarChartTitleForeground.  This enables animation, styling, binding, etc...
//    public static readonly DependencyProperty RadarChartTitleForegroundProperty =
//        DependencyProperty.Register("RadarChartTitleForeground", typeof(Brush), typeof(RadarChart), new PropertyMetadata(Brushes.Black));

//    /// <summary>
//    /// 雷达图大小
//    /// </summary>
//    public int RadarSize
//    {
//        get { return (int)GetValue(RadarSizeProperty); }
//        set { SetValue(RadarSizeProperty, value); }
//    }

//    // Using a DependencyProperty as the backing store for RadarSize.  This enables animation, styling, binding, etc...
//    public static readonly DependencyProperty RadarSizeProperty =
//        DependencyProperty.Register("RadarSize", typeof(int), typeof(RadarChart), new PropertyMetadata(10));

//    static RadarChart()
//    {
//        DefaultStyleKeyProperty.OverrideMetadata(typeof(RadarChart), new FrameworkPropertyMetadata(typeof(RadarChart)));
//    }
//    protected override void OnRender(DrawingContext drawingContext)
//    {
//        DrawPoints(RadarSize*3, drawingContext, true);
//        DrawPoints(RadarSize*2, drawingContext);
//        DrawPoints(RadarSize, drawingContext);

//        var myPen = new Pen
//        {
//            Thickness = 4,
//            Brush = Brushes.DodgerBlue
//        };
//        myPen.Freeze();
//        StreamGeometry streamGeometry = new StreamGeometry();
//        using (StreamGeometryContext geometryContext = streamGeometry.Open())
//        {
//            var h = this.ActualHeight / 2;
//            var w = this.ActualWidth / 2;
//            PointCollection points = new PointCollection();
//            foreach (var item in RadarArray)
//            {
//                var ss = new Point((item.PointValue.X - w) / 100 * item.ValueMax + w, (item.PointValue.Y - h) / 100 * item.ValueMax + h);
//                points.Add(ss);
//            }
//            geometryContext.BeginFigure(points[points.Count - 1], true, true);
//            geometryContext.PolyLineTo(points, true, true);
//        }

//        streamGeometry.Freeze();
//        SolidColorBrush rectBrush = new SolidColorBrush(Colors.LightSkyBlue);
//        rectBrush.Opacity = 0.5;
//        drawingContext.DrawGeometry(rectBrush, myPen, streamGeometry);
//    }
//    void DrawPoints(int circleRadius, DrawingContext drawingContext, bool isDrawText = false)
//    {
//        var myPen = new Pen
//        {
//            Thickness = 2,
//            Brush = Brushes.Gainsboro
//        };
//        myPen.Freeze();
//        StreamGeometry streamGeometry = new StreamGeometry();
//        using (StreamGeometryContext geometryContext = streamGeometry.Open())
//        {
//            var h = this.ActualHeight / 2;
//            var w = this.ActualWidth / 2;
//            PointCollection points = null;
//            if (isDrawText)
//                points = GetPolygonPoint(new Point(w, h), circleRadius, RadarArray.Count, drawingContext);
//            else
//                points = GetPolygonPoint(new Point(w, h), circleRadius, RadarArray.Count);
//            geometryContext.BeginFigure(points[points.Count - 1], true, true);
//            geometryContext.PolyLineTo(points, true, true);
//        }
//        streamGeometry.Freeze();
//        drawingContext.DrawGeometry(null, myPen, streamGeometry);
//    }
//    private PointCollection GetPolygonPoint(Point center, double r, int polygonBound, DrawingContext drawingContext = null)
//    {
//        double g = 18;
//        double perangle = 360 / polygonBound;
//        double pi = Math.PI;
//        List<Point> values = new List<Point>();
//        for (int i = 0; i < polygonBound; i++)
//        {
//            Point p2 = new Point(r * Math.Cos(g * pi / 180) + center.X, r * Math.Sin(g * pi / 180) + center.Y);
//            if (drawingContext != null)
//            {
//                FormattedText formattedText = new FormattedText(
//               RadarArray[i].Text,
//               CultureInfo.CurrentCulture,
//               FlowDirection.LeftToRight,
//               new Typeface(new FontFamily("Arial"), FontStyles.Normal, FontWeights.Thin, FontStretches.Normal),
//               20.001D, RadarChartTitleForeground,1.25d)
//                {
//                    MaxLineCount = 1,
//                    TextAlignment = TextAlignment.Justify,
//                    Trimming = TextTrimming.CharacterEllipsis
//                };
//                RadarArray[i].PointValue = p2;
//                if (p2.Y > center.Y && p2.X < center.X)
//                    drawingContext.DrawText(formattedText, new Point(p2.X - formattedText.Width - 5, p2.Y - formattedText.Height / 2));
//                else if (p2.Y < center.Y && p2.X > center.X)
//                    drawingContext.DrawText(formattedText, new Point(p2.X, p2.Y - formattedText.Height));
//                else if (p2.Y < center.Y && p2.X < center.X)
//                    drawingContext.DrawText(formattedText, new Point(p2.X - formattedText.Width - 5, p2.Y - formattedText.Height));
//                else if (p2.Y < center.Y && p2.X == center.X)
//                    drawingContext.DrawText(formattedText, new Point(p2.X - formattedText.Width, p2.Y - formattedText.Height));
//                else
//                    drawingContext.DrawText(formattedText, new Point(p2.X, p2.Y));
//            }
//            values.Add(p2);
//            g += perangle;
//        }
//        PointCollection pcollect = new PointCollection(values);
//        return pcollect;
//    }
//}

//public class RadarModel : NotifyBase
//{
//    public string Text { get; set; }

//    private int _valueMax;

//    public int ValueMax
//    {
//        get { return _valueMax; }
//        set
//        {
//            _valueMax = value;
//            DoNotify();
//        }
//    }
//    private Point _pointValue;

//    public Point PointValue
//    {
//        get { return _pointValue; }
//        set
//        {
//            _pointValue = value;
//            DoNotify();
//        }
//    }
//}